﻿using System;
using System.Collections.Generic;
using System.Text;

namespace net.xBei.Helper
{
    public static class BooleanHelper
    {
        public static bool GetBoolean(this object obj) {
            if (obj == null) return false;
            if(obj is string str) {
                return bool.TryParse(str, out var r) ? r : false;
            }
            if(obj is uint uintObj){
                return uintObj != 0;
            }
            if (obj is int intObj) {
                return intObj != 0;
            }
            if (obj is ulong ulongObj) {
                return ulongObj != 0;
            }
            if (obj is long) {
                return (long)obj != 0;
            }
            if (obj is float) {
                return (float)obj != 0;
            }
            if (obj is double) {
                return (double)obj != 0;
            }
            if (obj is decimal) {
                return (decimal)obj != 0;
            }
            //只要不是null
            return true;
        }
    }
}
